<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="utf-8" />
        <title>SearchTree - ESUI Demo</title>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../../../dep/esui/3.2.0-beta.2/demo/assets/google-code-prettify/prettify.css"/>
        <link rel="stylesheet" href="assets/themes/standard.css" />
        <!--[if lt IE 9]>
        <link rel="stylesheet" href="../../../dep/esui/3.2.0-beta.2/demo/assets/ie8.css"/>
        <![endif]-->
    </head>
<body>
    <div class="header">
        <h1 id="branding">ESUI SearchTree</h1>
    </div>
    <div class="ui-g main-container">
        <div id="side-bar" class="ui-u-1-5">
            <ul id="navigator" class="ui-nav">
            </ul>
        </div>
        <div id="main" class="ui-u-4-5">
            <h2>SearchTree</h2>
            <p>SearchTree描述</p>
            <div class="example">
                <div id="cantainer">
                    <div data-ui="type:SearchTree;id:tree"></div>
                </div>
            </div>
            <div>
                <button type="button" data-ui="id:value;type:Button;variants:primary">event</button>
                <span id="value"></span>
                <span id="doRender"></span>
                <button type="button" data-ui="id:dorender;type:Button;variants:primary">render</button>
            </div>
        </div>
    </div>
    <script src="../../../dep/esui/3.2.0-beta.2/demo/assets/loader/esl.js"></script>
    <script src="config.js"></script>
    <script src="../../../dep/esui/3.2.0-beta.2/demo/demo.js"></script>
    <script src="../../../dep/esui/3.2.0-beta.2/demo/assets/google-code-prettify/prettify.js"></script>
    <script id="main-js">
    require(
        [
            'esui',
            'SearchTree'
        ],
        function (esui, SearchTree) {
           var datasource = {
                id: '1',
                text: '百度',
                children:[
                    {
                        id: '2',
                        text: '联盟研发部',
                        children: [
                            { id: '21', text: 'RD' },
                            { id: '22', text: 'FE' },
                            { id: '23', text: 'QA' },
                            { id: '24', text: 'PM' }
                        ]
                    },
                    {
                        id: '3',
                        text: '贴吧事业部',
                        children: [
                            { id: '31', text: 'RD' },
                            { id: '32', text: 'FE' },
                            { id: '33', text: 'QA' },
                            { id: '34', text: 'PM' }
                        ]
                    },
                    {
                        id: '4',
                        text: '百度音乐'
                    }
                ]
            };
            esui.init(
                document.body,
                {
                    properties : {
                        tree: {
                            datasource: datasource,
                            selectMode: 'multiple',
                            checkboxes: true,
                            linkContent: 'abc',
                            hideRoot: false,
                            wideToggleArea: true,
                            variants: 'hoverable icon angle',
                            selectedNodes: ['1', '2', '21']
                        }
                    }
                }
            );
            esui.get('value').on(
                'click',
                function () {
                    var selectValue = esui.get('tree').getValue();
                    document.getElementById('value').innerHTML = selectValue.toString();
                }
            );

            esui.get('dorender').on(
                'click',
                function () {
                    var tree = esui.get('tree');
                    var newData = {
                        id: '1',
                        text: '百度',
                        children:[
                            {
                                id: '2',
                                text: '联盟研发部',
                                children: [
                                    { id: '21', text: 'RD' },
                                    { id: '22', text: 'FE' },
                                    { id: '23', text: 'QA' },
                                    { id: '24', text: 'PM' }
                                ]
                            }
                        ]
                    };
                    newData.children = tree.datasource.children.slice(0,1);
                    tree.setProperties({
                        datasource: newData,
                        selectedNodes: ['1', '2', '22']
                    });
                    // tree.repaint();
                }
            );        
        }
    );
    </script>
    <script src="sitemap.js"></script>
</body>
</html>
